package com.irdstudio.bhcredit.console.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.bhcredit.console.dao.PluginFtpConfDao;
import com.irdstudio.bhcredit.console.dao.domain.PluginFtpConf;
import com.irdstudio.bhcredit.console.service.api.PluginFtpConfService;
import com.irdstudio.bhcredit.console.service.vo.PluginFtpConfVO;
import com.irdstudio.ssm.framework.service.FrameworkService;
/**
 * <p>ServiceImpl: ftp插件信息配置表				<p>
 * @author fangmf
 * @date 2019-01-04
 */
@Service("pluginFtpConfServiceImpl")
public class PluginFtpConfServiceImpl implements PluginFtpConfService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PluginFtpConfServiceImpl.class);

	@Autowired
	private PluginFtpConfDao pluginFtpConfDao;
	
	/**
	 * 新增操作
	 */
	public int insertPluginFtpConf(PluginFtpConfVO inPluginFtpConfVo) {
		logger.debug("当前新增数据为:"+ inPluginFtpConfVo.toString());
		int num = 0;
		try {
			PluginFtpConf pluginFtpConf = new PluginFtpConf();
			beanCopy(inPluginFtpConfVo, pluginFtpConf);
			num = pluginFtpConfDao.insertPluginFtpConf(pluginFtpConf);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PluginFtpConfVO inPluginFtpConfVo) {
		logger.debug("当前删除数据条件为:"+ inPluginFtpConfVo);
		int num = 0;
		try {
			PluginFtpConf pluginFtpConf = new PluginFtpConf();
			beanCopy(inPluginFtpConfVo, pluginFtpConf);
			num = pluginFtpConfDao.deleteByPk(pluginFtpConf);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPluginFtpConfVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PluginFtpConfVO inPluginFtpConfVo) {
		logger.debug("当前修改数据为:"+ inPluginFtpConfVo.toString());
		int num = 0;
		try {
			PluginFtpConf pluginFtpConf = new PluginFtpConf();
			beanCopy(inPluginFtpConfVo, pluginFtpConf);
			num = pluginFtpConfDao.updateByPk(pluginFtpConf);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPluginFtpConfVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PluginFtpConfVO queryByPk(PluginFtpConfVO inPluginFtpConfVo) {
		
		logger.debug("当前查询参数信息为:"+ inPluginFtpConfVo);
		try {
			PluginFtpConf queryPluginFtpConf = new PluginFtpConf();
			beanCopy(inPluginFtpConfVo, queryPluginFtpConf);
			PluginFtpConf queryRslPluginFtpConf = pluginFtpConfDao.queryByPk(queryPluginFtpConf);
			if (Objects.nonNull(queryRslPluginFtpConf)) {
				PluginFtpConfVO outPluginFtpConfVo = beanCopy(queryRslPluginFtpConf, new PluginFtpConfVO());
				logger.debug("当前查询结果为:"+ outPluginFtpConfVo.toString());
				return outPluginFtpConfVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PluginFtpConfVO> queryAllOwner(PluginFtpConfVO pluginFtpConfVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PluginFtpConfVO> list = null;
		try {
			List<PluginFtpConf> pluginFtpConfs = pluginFtpConfDao.queryAllOwnerByPage(pluginFtpConfVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pluginFtpConfs.size());
			pageSet(pluginFtpConfs, pluginFtpConfVo);
			list = (List<PluginFtpConfVO>) beansCopy(pluginFtpConfs, PluginFtpConfVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PluginFtpConfVO> queryAllCurrOrg(PluginFtpConfVO pluginFtpConfVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PluginFtpConf> pluginFtpConfs = pluginFtpConfDao.queryAllCurrOrgByPage(pluginFtpConfVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pluginFtpConfs.size());
		List<PluginFtpConfVO> list = null;
		try {
			pageSet(pluginFtpConfs, pluginFtpConfVo);
			list = (List<PluginFtpConfVO>) beansCopy(pluginFtpConfs, PluginFtpConfVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PluginFtpConfVO> queryAllCurrDownOrg(PluginFtpConfVO pluginFtpConfVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PluginFtpConf> pluginFtpConfs = pluginFtpConfDao.queryAllCurrDownOrgByPage(pluginFtpConfVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pluginFtpConfs.size());
		List<PluginFtpConfVO> list = null;
		try {
			pageSet(pluginFtpConfs, pluginFtpConfVo);
			list = (List<PluginFtpConfVO>) beansCopy(pluginFtpConfs, PluginFtpConfVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
}
